<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 医疗预约系统</title>
    <link rel="stylesheet" href="statics/css/hisStyle.css">
    <style>
        body {
            background-color: #f5f7fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        .login-container {
            max-width: 400px;
            margin: 100px auto;
            padding: 40px;
            background: white;
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }
        .login-header h1 {
            color: #2c3e50;
            margin-bottom: 10px;
            font-size: 28px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #555;
            font-weight: bold;
            font-size: 14px;
        }
        .form-control {
            width: 100%;
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s, box-shadow 0.3s;
        }
        .form-control:focus {
            outline: none;
            border-color: #3498db;
            box-shadow: 0 0 5px rgba(52, 152, 219, 0.3);
        }
        .btn-login {
            width: 100%;
            padding: 12px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .btn-login:hover {
            background-color: #2980b9;
        }
        .register-link {
            text-align: center;
            margin-top: 20px;
        }
        .register-link a {
            color: #3498db;
            text-decoration: none;
            transition: color 0.3s;
        }
        .register-link a:hover {
            color: #2980b9;
            text-decoration: underline;
        }
        .error-message {
            color: #e74c3c;
            background-color: #fdf2f2;
            border: 1px solid #fecaca;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
            font-size: 14px;
        }
        .success-message {
            color: #27ae60;
            background-color: #f0f9f0;
            border: 1px solid #c3e6c3;
            padding: 10px;
            border-radius: 5px;
            margin-bottom: 20px;
            font-size: 14px;
        }
        @media (max-width: 768px) {
            .login-container {
                margin: 50px 20px;
                padding: 30px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container">
        <div class="login-header">
            <h1>医疗预约系统</h1>
            <p>用户登录</p>
        </div>

        <!-- 错误提示 -->
        <c:if test="${not empty error}">
            <div class="error-message">
                ${error}
            </div>
        </c:if>

        <!-- 成功提示 -->
        <c:if test="${not empty success}">
            <div class="success-message">
                ${success}
            </div>
        </c:if>

        <form action="auth/login" method="post" id="loginForm">
            <div class="form-group">
                <label for="phone">手机号：<span style="color: #e74c3c;">*</span></label>
                <input type="tel" id="phone" name="phone" class="form-control" required pattern="1[3-9]\d{9}" placeholder="请输入手机号码">
            </div>
            <div class="form-group">
                <label for="password">密码：<span style="color: #e74c3c;">*</span></label>
                <input type="password" id="password" name="password" class="form-control" required minlength="6" placeholder="请输入密码">
            </div>
            <button type="submit" class="btn-login">登录</button>
        </form>

        <script>
            // 显示注册成功提示
            const urlParams = new URLSearchParams(window.location.search);
            if (urlParams.has('registered')) {
                alert('注册成功！欢迎使用我们的服务。');
            }
            
            // 表单验证
            document.getElementById('loginForm').addEventListener('submit', function(e) {
                const phone = document.getElementById('phone').value;
                const password = document.getElementById('password').value;
                
                // 手机号验证
                const phoneRegex = /^1[3-9]\d{9}$/;
                if (!phoneRegex.test(phone)) {
                    alert('请输入有效的手机号码');
                    e.preventDefault();
                    return;
                }
                
                // 密码验证
                if (password.length < 6) {
                    alert('密码长度不能少于6位');
                    e.preventDefault();
                    return;
                }
            });
        </script>

        <div class="register-link">
            <p>还没有账号？<a href="auth/register">立即注册</a></p>
        </div>
    </div>
</body>
</html>
